 package com.nanuminc.market.today;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;


import com.nanuminc.market.R;

     	public class TodayLocationCity_ngoc extends ListActivity implements OnItemClickListener {
     	  
     	  private ListView mLv_CityList ;
     	  private ArrayAdapter<String> listAdapter ;
     	  Context mContext;
     	  String[] loc;
     	  
     	  /** Called when the activity is first created. */
     	  @Override
     	  public void onCreate(Bundle savedInstanceState) {
     	    super.onCreate(savedInstanceState);
    		requestWindowFeature(Window.FEATURE_NO_TITLE); // Q
     	    setContentView(R.layout.location_city_ngoc); // View 내용 Activity에 박기
     	         	    
         	mLv_CityList = (ListView) findViewById(android.R.id.list);
     	    loc = getResources().getStringArray(R.array.loc_all_info_ngoc);  //without this, the content can not be viewed on screen
     	    listAdapter = new MyArrayAdapter(this);      	    		
      	   	mLv_CityList.setAdapter( listAdapter );            	   	      	   
      	   	mLv_CityList.setOnItemClickListener( new ListViewItemClickListener() );
      	   	      	   	
      	   	/**mLv_CityList.setOnItemClickListener(new OnItemClickListener() { 
      	          public void onItemClick(AdapterView<?> parent, View view, 
      	              int position, long id) { 
      	        	  Intent i = new Intent(getApplicationContext(), TodayLocationDistric_ngoc.class);
      	        	  String cityName = ((TextView) view).getText().toString();
      	        	  i.putExtra("city_name", cityName);
      	        	  i.putExtra("city_position", position);
      	        	  startActivity(i);
      	        	  //	Toast.makeText(parent.getContext(), "hello" + position, Toast.LENGTH_LONG).show();    	  
      	          	  } 
      	        }); **/ 
      	   
     	  }
		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			// TODO Auto-generated method stub
			
		}
		
		
		public class ListViewItemClickListener implements AdapterView.OnItemClickListener{
	        @Override
	        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {	        		        
	        	Intent i = new Intent(getApplicationContext(), TodayLocationDistric_ngoc.class);
				i.putExtra("city_name",  loc[position].toString());
				i.putExtra("city_position", position);
				startActivity(i);
	        }        
	    }

		
		
		class MyArrayAdapter extends ArrayAdapter<String>{
     		Context context;
     		TextView city;     	     		
     		MyArrayAdapter(Context context){
     			super(context, R.layout.list_view_loc, loc);
     			this.context = context;
     		}     		
     		public View getView(int position, View convertView, ViewGroup parent){
     			View row = convertView;     			     			
     			if (row == null) {
     				LayoutInflater inflater = ((Activity)context).getLayoutInflater();
     				row= (View)inflater.inflate(R.layout.list_view_loc, null);}     			
     			city = (TextView)row.findViewById(R.id.city_name);
     			city.setText(loc[position]);     			
     			return row;
     		}     		
     	}			
     	}
     	
     	